<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>字典管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />
</head>
<body class="childrenBody">


<form class="layui-form" action="">
	<div class="layui-form-item searchLine">
		<div class="layui-inline">
			<label class="layui-form-label">访问路径/实体类</label>
			<div class="layui-input-inline">
				<input type="text" placeholder="请输入访问路径/实体类" value="${path}" id="path" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">标题描述</label>
			<div class="layui-input-inline">
				<input type="text" placeholder="请输入标题描述" value="${sysTableVo.tableComment}" id="title" class="layui-input">
			</div>
		</div>
	</div>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>编辑内容</legend>
	</fieldset>
	<#list sysUseColumnList as sysColumn>
		<div class="layui-form-item searchLine">
			<div class="layui-inline">
				<label class="layui-form-label">名称</label>
				<div class="layui-input-inline">
					<input type="text" placeholder="请输入名称" value="${sysColumn.columnComment}" class="layui-input name">
				</div>
				<label class="layui-form-label">name值</label>
				<div class="layui-input-inline">
					<input type="text" placeholder="请输入name值" value="${sysColumn.columnName}" class="layui-input keyword">
				</div>
				<label class="layui-form-label">开启搜索框</label>
				<div class="layui-input-inline">
					<select class="status" lay-filter="status">
						<option value="0">否</option>
						<option value="1">是</option>
					</select>
				</div>
				<label class="layui-form-label hide1" style="display: none;">类型</label>
				<div class="layui-input-inline hide1"  style="display: none;">
					<select class="type" lay-filter="type">
						<option value="input">输入框</option>
						<option value="select">下拉框</option>
						<option value="textarea">文本框</option>
					</select>
				</div>
				<label class="layui-form-label hide2"  style="display: none;">下拉框字典码</label>
				<div class="layui-input-inline hide2"  style="display: none;">
					<input type="text" name="code" placeholder="请输入字典码" class="layui-input code">
				</div>
			</div>
		</div>
	</#list>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="submitBtn">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>
<div style="width: 100%">
	<textarea style="width: 100%; height: 300px;" id="showPage"></textarea>
</div>

<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">
    layui.use(['form','jquery','checkUtil','baseUtil'], function() {
        var form = layui.form,
            $ = layui.jquery,
            checkUtil = layui.checkUtil,
            baseUtil = layui.baseUtil;
        form.on('select(status)', function(data){
            if(data.value==1){
                $(data.elem).parent().parent().find(".hide1").show();
			}else{
                $(data.elem).parent().parent().find(".hide1").hide();
                $(data.elem).parent().parent().find(".hide2").hide();
			}
        });
        form.on('select(type)', function(data){
            if(data.value=="select"){
                $(data.elem).parent().parent().find(".hide2").show();
            }else{
                $(data.elem).parent().parent().find(".hide2").hide();
            }
        });
        //监听提交
        form.on('submit(submitBtn)', function(data){
            var showPage='<!DOCTYPE html><html><head><meta charset="utf-8"><title>'+$("#title").val()+'</title><meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'+
                '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">'+
                '<meta name="apple-mobile-web-app-status-bar-style" content="black">'+
                '<meta name="apple-mobile-web-app-capable" content="yes">'+
                '<meta name="format-detection" content="telephone=no">'+
                '<link rel="stylesheet" href="$\{s.base}/js/layui/css/layui.css" media="all" />'+
                '<link rel="stylesheet" href="$\{s.base}/css/base/base.css" media="all" />'+
                '</head>'+
                '<body class="childrenBody">';
            showPage+=createTool();
            showPage+='</body></html>';
            $("#showPage").val(showPage);
            return false;
        });
        /**
		 * 创建工具栏
		 * */
        function createTool() {
            var searchContent="";
            $(".searchLine").each(function (index,obj) {
                var name=$(obj).find(".name").val();
                var keyword=$(obj).find(".keyword").val();
                var status=$(obj).find(".status").val();
                var type=$(obj).find(".type").val();
                var code=$(obj).find(".code").val();
                if(status=="1"){
                    if(checkUtil.isEmpty(code)){
                        code="";
                    }
                    //开启
                    if(checkUtil.isNotEmpty(searchContent)){
                        searchContent+=',{"name":"'+name+'","type":"'+type+'","id":"'+keyword+'","code":"'+code+'"}'
                    }else{
                        searchContent='{"name":"'+name+'","type":"'+type+'","id":"'+keyword+'","code":"'+code+'"}'
                    }
                }
            });
            if(checkUtil.isNotEmpty(searchContent)){
                var path=$("#path").val();
                selectJson=JSON.parse('['+searchContent+']');
               return createSeacher(selectJson,path);
            }
        }
		var codes="";
        /**
		 * 工具栏
		 * */
        function createSeacher(selectJson,path) {
            var strSelect='<form class="layui-form"><input type="hidden" id="id" name="id" value="$/{'+path+'.id}" />';
            if(selectJson!=null){
                selectJson.forEach(function(e,i){
                    strSelect+='<div class="layui-form-item layui-row layui-col-xs12">'+
                        '<label class="layui-form-label"><span class="red">*</span>&nbsp;&nbsp;'+e.name+'</label>'+
                    '<div class="layui-input-block">';
                    if(e.type=="select"){
                        if(checkUtil.isEmpty(codes)){
                            codes=e.code;
                        }else{
                            if(!(codes.indexOf(e.code)>-1)){
                                codes+=","+e.code;
                            }
                        }
                        strSelect+='<select class="form-control" name="'+e.id+'" lay-verify="required" id="'+e.id+'"></select>';
                    }else if(e.type=="textarea"){
                        strSelect+='<textarea class="layui-textarea" name="'+e.id+'" lay-verify="content" placeholder="请输入'+e.name+'">$/{'+path+'.'+e.id+'}</textarea>';
                    }else{
                        strSelect+='<input type="text"  class="layui-input"  name="'+e.id+'" value="$/{'+path+'.'+e.id+'}" placeholder="请输入'+e.name+'"  lay-verify="required" autocomplete="off"/>';
                    }
                    strSelect+='</div></div>';
                });
            }
            strSelect+='<div class="layui-form-item layui-row layui-col-xs12">'+
                '<div class="layui-input-block">'+
                '<button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="submitBtn">确定</button>'+
                '<button type="reset" class="layui-btn layui-btn-sm layui-btn-primary cancel">取消</button>'+
                '</div>'+
                '</div>'+
                '</form>';
            strSelect+='<scriptTag type="text/javascript" src="$/{s.base}/js/layui/layui.js"></scriptTag>'+
						'<scriptTag type="text/javascript" src="$/{s.base}/js/base/base.js"></scriptTag>'+
						'<scriptTag type="text/javascript">';
            strSelect+="layui.use(['form', 'jquery','baseUtil','pageUtil'], function() {"+
            	"var form = layui.form,$ = layui.jquery,baseUtil = layui.baseUtil,pageUtil = layui.pageUtil;"
            if(checkUtil.isNotEmpty(codes)){
                strSelect+='pageUtil.initDict("'+codes+'",function (dictData) {';
                if(selectJson!=null){
                    selectJson.forEach(function(e,i){
                        if(e.type=="select"){
                            strSelect+='pageUtil.showDict($("#'+e.id+'"), pageUtil.aceeptDictContentList(dictData, "'+e.code+'"), "",\'$/{'+path+'.'+e.id+'}\');';
                        }
                    });
                }
                strSelect+='});';
            }

            strSelect+='form.on(\'submit(submitBtn)\', function(data){'+
            'baseUtil.postMethodResult("/'+path+'/addOrUpdate",data.field,function (result) {'+
                'parent.location.reload();'+
            '});'+
            'return false;'+
        '});});</scriptTag>';

            return strSelect;
        }
    });
</script>
</body>
</html>